from sqlmodel import SQLModel, Field, Index
from datetime import datetime

class SwapRecord(SQLModel, table=True):
    """WaveUp兑换记录"""
    __tablename__ = "t_swap_record"  # 对应数据库表名

    # 索引定义（优化查询性能）
    __table_args__ = (
        Index("idx_swapOrderNo", "swapOrderNo", unique=True, info="兑换订单号唯一索引"),
        Index("idx_productPairId", "productPairId", info="产品交易对ID索引"),
        Index("idx_uid", "uid", info="用户ID索引"),
    )

    # 字段定义
    id: int = Field(default=None, primary_key=True, description="主键ID")
    swapOrderNo: str = Field(default="", index=True, description="兑换订单号")
    productPairId: str = Field(default="", index=True, description="交易对编码")
    uid: int = Field(default=0, index=True, description="用户ID")
    fromProductId: str = Field(default="", description="换入藏品ID")
    fromAmount: float = Field(default=0.0, description="换入藏品数量")
    toProductId: str = Field(default="", description="换出藏品ID")
    toAmount: float = Field(default=0.0, description="换出藏品数量")
    slippage: float = Field(default=0.0, description="滑点比例")
    wpSwapId: str = Field(default="", description="waveup兑换记录ID")
    profitAmount: float = Field(default=0.0, description="套利收益")
    exchangeType: int = Field(default=0, description="兑换类型 0:A->B 1:B->A")
    dealValue: float = Field(default=0.0, description="成交金额")
    fee: float = Field(default=0.0, description="手续费（平台手续费+流动性池手续费）")
    status: int = Field(default=0, description="兑换状态 0:待处理 1:已完成 2:兑换失败")
    createdAt: datetime = Field(default_factory=datetime.now, description="创建时间")
    updatedAt: datetime = Field(default_factory=datetime.now, description="更新时间")
